# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libsodium
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.18
pkgrel=1
pkgdesc="P(ortable|ackageable) NaCl-based crypto library (mingw-w64)"
arch=("any")
url="https://github.com/jedisct1/libsodium"
license=('custom:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://download.libsodium.org/libsodium/releases/${_realname}-${pkgver}.tar.gz")
sha256sums=('6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make -k check || true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
